class MagicBox07<T : Human>(vararg item: T) {
    //随机产生一个对象，如果不是指定类型的对象，就通过backup函数生成一个指定类型的对象
    inline fun <reified T> randomOrBackup(backup: () -> T): T {
        val items = listOf(Boy07("jack", 20), Man04("john", 35))
        val random = items.shuffled().first()
        println(random)
        return if (random is T) {
            random
        } else {
            backup()
        }
    }
}

open class Human04(val age: Int)
class Boy07(val name: String, age: Int) : Human(age){
    override fun toString(): String {
        return "Boy07(name='$name')"
    }
}

class Man04(val name: String, age: Int) : Human(age){
    override fun toString(): String {
        return "Man04(name='$name')"
    }
}

fun main() {
    val box1: MagicBox07<Man04> = MagicBox07()
    val subject = box1.randomOrBackup {
        Boy07("jimmy", 39)
    }
    println(subject)

}